<%@ page contentType="text/html;charset=utf-8"%>
<%@page import="com.cs.beneficios.common.ConnectionFactory,com.cs.beneficios.common.entity.Consultas,java.sql.SQLException,java.sql.Connection,java.sql.ResultSet,com.cs.beneficios.common.entity.database"%>
<script language="JavaScript" src="<%= request.getContextPath() + "/js/calendar6.js" %>"></script>
<script language="JavaScript" src="<%= request.getContextPath() + "/js/popUP.js" %>"></script>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>untitled</title>
    <script language="javascript">
    
 //Validacion campos vacios 
  
    function checkFields() {
      missinginfo = "";
      if (document.frmIngresarSede.sede.value == "") {
        alert("Debe ingresar el nombre para la sede!!");
        document.frmIngresarSede.sede.focus() 
        return false;
      }
      if (document.frmIngresarSede.dirEncasillada.value == "") {
        alert("Debe ingresar la direccion encasillada!!");
        document.frmIngresarSede.viaTipo.focus() 
        return false;
      }
      
      
      
      
     /*if (document.frmIngresarSede.dirdescriptiva.value == "") {
      missinginfo += "\n     -  Direccion Descriptiva";
      }
      if (missinginfo != "") {
      alert("Debe ingresar una direccion descriptiva para la sede!!");
      return false;
      }
      if (document.frmIngresarSede.direncasillada.value == "") {
      missinginfo += "\n     -  Direccion Encasillada";
      }
      if (missinginfo != "") {
      alert("Debe ingresar la direccion ensillada de la Sede!!");
      return false;
      }    */ 
      var fecha1 = new String(document.frmIngresarSede.desde.value);
      var fecha2 = new String(document.frmIngresarSede.hasta.value);
      var posterior = "";
      var anterior = "";
      var arrayFecha = fecha2.split("-");
      posterior = arrayFecha[0]+arrayFecha[1]+arrayFecha[2];
      arrayFecha = fecha1.split("-");
      anterior = arrayFecha[0]+arrayFecha[1]+arrayFecha[2];
      
      if (parseInt(anterior)>=parseInt(posterior)){
        alert("La fecha Desde Vigencia es mayor a la fecha Hasta Vigencia.") 
         return false;
      }
      
       //Valida que la fecha Inicial no sea menor a la fecha de hoy
       var Actual = "";
       var hoy = new Date();
       var dia = eval(hoy.getDate());
           if (dia<10)
            	dia = "0" + dia;
        var mes = eval(hoy.getMonth()+1);
          if (mes<10)
             	mes = "0" + mes;
       var fechaActual= hoy.getYear() + "-" + mes + "-" + dia;
       var arrayFecha = fechaActual.split("-");
       Actual= arrayFecha[0]+arrayFecha[1]+arrayFecha[2];
       if(parseInt(anterior)<parseInt(Actual)) {     
          alert("La fecha inicial es menor a la fecha de hoy!!! ") 
          return false; 
        }
      
      document.frmIngresarSede.submit();
     }    
     
  function agregar(object,origen)
  {
    document.frmIngresarSede.dirdescriptiva.value="";
    document.frmIngresarSede.dirdescriptiva.disabled = true;
    if(document.frmIngresarSede.viaTipo.value==0){
      alert('El tipo no es valido.')
      return;
    }
    if(origen == 'tipo') tipo = object.value.toUpperCase();
    if(origen == 'vNro'){
      if(object.value.length == 1) object.value='00'+object.value;
      if(object.value.length == 2) object.value='0'+object.value;
      vNro = object.value.toUpperCase();
    }
    if(origen == 'vOr') vOr = object.value.toUpperCase();
    if(origen == 'vApn'){
      if(object.value.length == 1) object.value=' '+object.value;
      vApn = object.value.toUpperCase();
    }
    if(origen == 'cOr') cOr = object.value.toUpperCase();
    if(origen == 'cNro'){
      if(object.value.length == 1) object.value='00'+object.value;
      if(object.value.length == 2) object.value='0'+object.value;
      cNro = object.value.toUpperCase();
    }
    if(origen == 'cApn') {
      if(object.value.length == 1) object.value=' '+object.value;
      cApn = object.value.toUpperCase();
    }
    if(origen == 'placa'){
      if(object.value.length == 1) object.value='00'+object.value;
      if(object.value.length == 2) object.value='0'+object.value;
      placa = object.value.toUpperCase();
    }
    if(origen == 'interior'){
      if(object.value.length == 1) object.value='0000'+object.value;
      if(object.value.length == 2) object.value='000'+object.value;
      if(object.value.length == 3) object.value='00'+object.value;
      if(object.value.length == 4) object.value='0'+object.value;
      interior = object.value.toUpperCase();
    }
    if(origen == 'bloque'){
      if(object.value.length == 1) object.value='0'+object.value;
      bloque = object.value;
    }

    document.frmIngresarSede.dirEncasillada.value =  tipo+" "+vOr+vNro+" "+vApn+"   "+cOr+cNro+" "+cApn+" "+placa+" "+bloque+interior;
  }

    </script>
    
  </head>
  <body>
   <link href="<%= request.getContextPath() + "/css/bloques.css" %>" rel="stylesheet" type="text/css">
    <P></P>
    <P></P>
    <P align="center"></P>
    <P align="center" class="titulosenblanco">ADMINISTRACION DE SEDES</P>
    <P align="center"></P>
    <DIV align="center">
    <form name="frmIngresarSede" method="POST" action="<%=request.getContextPath()+"/Sedes/GuardarSede.do"%>">
     <input type="hidden" name="codsede" />
      <table cellspacing="3" cellpadding="3" border="0" width="60%" align="center">
        <tr>
          <td width="6%"></td>
          <td width="35%" class="celdatabla">Nombre (*)</td>
          <td width="68%">
            <input type="text" class="form" name="sede" maxlength="70" size="70"/>
          </td>
        </tr>
        <tr>
          <td width="6%"></td>
          <td width="35%" class="celdatabla">Subsede</td>
          <td width="68%">
            <input type="text" Class="form" maxlength="40" size="40" name="subsede" readonly/>
            <a href='javascript:vpopUsers("<%=request.getContextPath()+"/jsp/sedes/Subsede.jsp"%>");'>
            <img border="0" src="<%= request.getContextPath() + "/images/sede.GIF" %>" alt="Seleccionar una Sede" width="16" height="16" /></a>
          </td>
        </tr>
        <tr>
          <td width="6%"></td>
          <td width="35%" class="celdatabla">Descripcion</td>
          <td width="68%">
            <textarea name="descripcion"  class="form" cols="40" rows="7"></textarea>
          </td>
        </tr>
 <%
  
 //ConnectionFactory cf = new ConnectionFactory("beneficios","beneficios");
 ConnectionFactory cf = new ConnectionFactory();
 Consultas consultas = new Consultas(cf);
 ResultSet rs = null;
 rs = consultas.getMunicipios();
 
 if(rs!=null)
 %>         
        <tr>
          <td width="6%"></td>
          <td width="35%" class="celdatabla">Municipio (*)</td>
          <td width="68%">
            <select name="municipio"/>
            
            <% try {
               while(rs.next()){%>
              <option class="form" value="<%=rs.getString("codigo")%>"><%=rs.getString("nombre")%></option>
              <%}%>
            </select>
         <% }catch(SQLException e){
               e.printStackTrace();
              } %>  
          </td>
        </tr>
        <tr>
          <td width="6%"></td>
          <td width="35%" class="celdatabla">Tipo</td>
          <td width="68%">
            <input type="text" class="form" name="tipo" maxlength="30" size="30"/>
          </td>
        </tr>
        <tr>
          <td width="6%"></td>
          <td width="35%" class="celdatabla">C&aacute;racter &nbsp;&nbsp;</td>
          <td width="68%">
            <select name="caracter" class="formLista">
              <option value="Publica">Publica</option>
              <option value="Privada">Privada</option>
              <option value="Otra">Otra</option>
            </select>
          </td>
        </tr>
        <tr>
          <td width="6%"></td>
          <td width="35%" class="celdatabla" colspan="2">
            <P>Direcci&oacute;n Encasillada&nbsp;&nbsp; (*) &nbsp;&nbsp;</P>
          </td>
        </tr>
        <tr>
             <td width="28%">&nbsp;</td>
             <td colspan="3" class="celdatabla">
               <table cellspacing="3" align="left" cellpadding="2" border="1" width="48%">
                 <tr>
                   <td colspan="4">
                     <DIV align="center">
                       <STRONG>Datos de la via</STRONG> 
                     </DIV>
                   </td>
                   <td colspan="3">
                     <DIV align="center">
                       <STRONG>Datos del cruce</STRONG>
                     </DIV>
                   </td>
                   <td colspan="3">
                     <DIV align="center">
                       <STRONG>Datos adicionales</STRONG>
                     </DIV>
                   </td>
                 </tr>
                 <tr>
                   <td>
                     <DIV align="center">Tipo</DIV>
                   </td>
                   <td>
                     <DIV align="center">Or.</DIV>
                   </td>
                   <td>
                     <DIV align="center">Nro.</DIV>
                   </td>
                   <td>
                     <DIV align="center">Apn.</DIV>
                   </td>
                   <td>
                     <DIV align="center">Or.</DIV>
                   </td>
                   <td>
                     <DIV align="center">Nro.</DIV>
                   </td>
                   <td>
                     <DIV align="center">Apn.</DIV>
                   </td>
                   <td>
                     <DIV align="center">Placa</DIV>
                   </td>
                   <td>
                     <DIV align="center">Bloque</DIV>
                   </td>
                   <td>
                     <DIV align="center">Interior</DIV>
                   </td>

                 </tr>
                 <tr>
                   <td>
                     <% String tipo = request.getParameter("viaTipo"); %>  
                     <select size="1" name="viaTipo" onchange="agregar(this,'tipo')"  onmouseover="this.T_WIDTH=180;this.T_TITLE='Tipo de via';return escape('Corresponde al tipo de via.')" class="form">
                     <% if((Object)tipo != null){
                            if(tipo.equals("0")){%>
                             <option value="0" selected="selected"></option>
                          <%}else{%>
                             <option value="0"></option>
                          <%}%>
                          <% if(tipo.equals("CR")){%>
                             <option value="CR" selected="selected">Carrera</option>
                          <%}else{%>
                             <option value="CR">Carrera</option>
                          <%}%>
                          <% if(tipo.equals("CL")){%>
                             <option value="CL" selected="selected">Calle</option>
                          <%}else{%>
                             <option value="CL">Calle</option>
                           <%}%>
                          <% if(tipo.equals("CQ")){%>  
                             <option value="CQ" selected="selected">Circular</option>
                          <%}else{%>
                             <option value="CQ">Circular</option>
                           <%}%>
                          <% if(tipo.equals("TR")){%>
                             <option value="TR" selected="selected">Transversal</option>
                          <%}else{%>
                             <option value="TR" >Transversal</option>
                           <%}%>
                          <% if(tipo.equals("DG")){%>
                             <option value="DG" selected="selected">Diagonal</option>
                          <%}else{%>
                             <option value="DG">Diagonal</option>
                           <%}%>
                          <% if(tipo.equals("AV")){%>
                             <option value="AV" selected="selected">Avenida</option>
                          <%}else{%>
                             <option value="AV">Avenida</option>
                          <%}
                          }else{%>
                            <option value="0"></option>
                            <option value="CR">Carrera</option>
                            <option value="CL">Calle</option>
                            <option value="CQ">Circular</option>
                            <option value="TR" >Transversal</option>
                            <option value="DG">Diagonal</option>
                            <option value="AV">Avenida</option>
                          <%}%>
                     </select>
                   </td>
                   <td>
                   <% String vOr = request.getParameter("viaOrientacion"); %>  
                     <select size="1" class="form" onchange="agregar(this,'vOr')" name="viaOrientacion" onmouseover="this.T_WIDTH=180;this.T_TITLE='Orientacion de la via';return escape('Corresponde a la orientacion de la via.')">
                     <% if((Object)vOr != null){
                            if(vOr.equals("0")){%>
                       <option value="0" selected="selected"></option>
                    <%}else{%>
                       <option value="0"></option>
                    <%}%>
                    <% if(vOr.equals("E")){%>
                       <option value="E" selected="selected">Este</option>
                    <%}else{%>
                       <option value="E">Este</option>
                    <%}%>
                    <% if(vOr.equals("S")){%>
                       <option value="S" selected="selected">Sur</option>
                    <%}else{%>
                       <option value="S">Sur</option>
                     <%}
                    }else{%>  
                       <option value="0"></option>
                       <option value="E">Este</option>
                       <option value="S">Sur</option>
                    <%}%>
                     </select>
                   </td>
                   <td>
                   <% String vNro = request.getParameter("vNro"); 
                      if((Object)vNro == null) vNro = "";
                   %>  
                     <input type="text" value="<%=vNro%>" onchange="agregar(this,'vNro')" name="vNro" class="form" maxlength="3" size="3" onmouseover="this.T_WIDTH=180;this.T_TITLE='Numero de la via';return escape('Corresponde al numero de la via.')"/>
                   </td>       
                   <td>
                   <% String vAp = request.getParameter("viaApendice"); 
                      if((Object)vAp == null) vAp = "";
                   %>  
                     <input type="text" value="<%=vAp%>" class="form" size="2" maxlength="2"  name="viaApendice" onchange="agregar(this,'vApn')" onmouseover="this.T_WIDTH=180;this.T_TITLE='Apendice de la via';return escape('Corresponde al apendice; ejemplo: A, AA, B, BB etc.')"/>
                   </td>
                   <td>
                     <DIV align="center">
                     <% String cOr = request.getParameter("cruceOrientacion"); %>  
                       <select size="1" class="form" name="cruceOrientacion" onchange="agregar(this,'cOr')" onmouseover="this.T_WIDTH=180;this.T_TITLE='Orientacion del cruce';return escape('Corresponde a la orientacion del cruce.')">
                         <% if((Object)cOr != null){
                            if(cOr.equals("0")){%>
                       <option value="0" selected="selected"></option>
                    <%}else{%>
                       <option value="0"></option>
                    <%}%>
                    <% if(cOr.equals("E")){%>
                       <option value="E" selected="selected">Este</option>
                    <%}else{%>
                       <option value="E">Este</option>
                    <%}%>
                    <% if(cOr.equals("S")){%>
                       <option value="S" selected="selected">Sur</option>
                    <%}else{%>
                       <option value="S">Sur</option>
                     <%}
                    }else{%>  
                       <option value="0"></option>
                       <option value="E">Este</option>
                       <option value="S">Sur</option>
                    <%}%>
                       </select>
                     </DIV>
                   </td>
                   <td>
                     <DIV align="center">
                      <% String cNro = request.getParameter("cruceNumero"); 
                      if((Object)cNro == null) cNro = "";
                      %>  
                       <input type="text" value="<%=cNro%>" class="form" size="3" maxlength="3" name="cruceNumero" onchange="agregar(this,'cNro')" onmouseover="this.T_WIDTH=180;this.T_TITLE='Numero del cruce';return escape('Primer numero de la placa de la puerta.')"/>
                     </DIV>
                   </td>
                   <td>
                     <DIV align="center">
                     <% String cAp = request.getParameter("cruceApendice"); 
                      if((Object)cAp == null) cAp = "";
                    %>  
                       <input type="text" value="<%=cAp%>" class="form" maxlength="2" size="2" name="cruceApendice" onchange="agregar(this,'cApn')" onmouseover="this.T_WIDTH=180;this.T_TITLE='Apendice del cruce';return escape('Corresponde al apendice; ejemplo: A, AA, B, BB etc.')"/>
                     </DIV>
                   </td>
                   <td>
                     <DIV align="center">
                    <% String placa = request.getParameter("placa"); 
                      if((Object)placa == null) placa = "";
                    %>  
                       <input type="text" value="<%=placa%>" size="3" maxlength="3" name="placa" onchange="agregar(this,'placa')" class="form" onmouseover="this.T_WIDTH=180;this.T_TITLE='Placa';return escape('Es el segundo numero de la puerta y que corresponde a la distancia que existe entre la esquina y la propiedad.')"/>
                     </DIV>
                   </td>
                   <td>
                     <DIV align="center">
                    <% String bloque = request.getParameter("bloque"); 
                      if((Object)bloque == null) bloque = "";
                    %>
                       <input type="text" value="<%=bloque%>" class="form" maxlength="2" name="bloque" onchange="agregar(this,'bloque')" size="2" onmouseover="this.T_WIDTH=180;this.T_TITLE='Bloque';return escape('Aplica para edificios o unidades residenciales.')"/>
                     </DIV>
                   </td>
                   <td>
                     <DIV align="center">
                     <% String interior = request.getParameter("interior"); 
                      if((Object)interior == null) interior = "";
                     %>
                       <input type="text" value="<%=interior%>" class="form" size="5" name="interior" onchange="agregar(this,'interior')" maxlength="5" onmouseover="this.T_WIDTH=180;this.T_TITLE='Interior';return escape('El numero de apartamento, si es el caso.')"/>
                     </DIV>
                   </td>

                 </tr>
                 <tr>
                    <td colspan="10">
                      <DIV align="center">
                        <STRONG>Direccion Generada
                        </STRONG>
                      </DIV>
                    </td>
                 </tr>
                 <tr>
                 <% String dire = request.getParameter("dirEncasillada"); 
                      if((Object)dire == null) dire = "";
                     %>
                    <td colspan="10">
                      <DIV align="center"><input type="text"  name="dirEncasillada" class="form" value="<%=dire%>" size="40">
                      </DIV>
                    </td>
                 </tr>
               </table>
             </td>
           </tr>
        <tr>
          <td width="6%"></td>
          <td width="35%" class="celdatabla">Direcci&oacute;n &nbsp;Descriptiva&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
          <td width="68%">
           <input type="text" class="form"  name="dirdescriptiva" maxlength="30" size="30"/>
          </td>
        </tr>
        <tr>
          <td width="6%"></td>
          <td width="35%" class="celdatabla">Localizacion COBAMA &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
          <td width="68%">
            <input type="text" class="form"  name="cobama" maxlength="25" size="25"/>
          </td>
        </tr>
         <tr>
           <td width="6%"></td>
          <td width="35%" class="celdatabla">Desde Vigencia</td>
          <td width="68%">
            <input type="text" class="form"  name="desde" maxlength="11" size="11"/>
              <a href="javascript:effectiveFrom1.popup();">
                <img src="<%= request.getContextPath() + "/images/cal.gif" %>" 
                 width="16" height="16" border="0" alt="Click para seleccionar la fecha"></a>
          </td>
        </tr>
        </tr>
         <tr>
           <td width="6%"></td>
          <td width="35%" class="celdatabla">Hasta Vigencia</td>
          <td width="68%">
            <input type="text" Class="form"  name="hasta" maxlength="11" size="11"/>
              <a href="javascript:effectiveUntil1.popup();">
              <img src="<%= request.getContextPath() + "/images/cal.gif" %>" 
             width="16" height="16" border="0" alt="Click para seleccionar la fecha"></a>
          </td>
        </tr>
        <tr>
           <td width="6%"></td>
          <td width="35%"></td>
          <td width="68%"></td>
        </tr>
        <tr>
          <td width="6%"></td>
          <td width="27%">&nbsp;
          </td>
          <td width="68%">
            <input type="button" value="Guardar" name="Guardar"  onclick="checkFields()"/>
          </td>
        </tr>
      </table>
      <P>
        <script language="javascript">
    
    var effectiveFrom1 = new calendar1(document.forms['frmIngresarSede'].elements['desde'],"-",'<%=request.getContextPath()+"/js/"%>');
    var effectiveUntil1 = new calendar1(document.forms['frmIngresarSede'].elements['hasta'],"-",'<%=request.getContextPath()+"/js/"%>');
               
    
  var tipo = document.frmIngresarSede.viaTipo.value;
  var vNro = document.frmIngresarSede.vNro.value;
  var vOr = document.frmIngresarSede.viaOrientacion.value;
  var vApn = document.frmIngresarSede.viaApendice.value;
  var cOr = document.frmIngresarSede.cruceOrientacion.value;
  var cNro = document.frmIngresarSede.cruceNumero.value;
  var cApn = document.frmIngresarSede.cruceApendice.value;
  var placa = document.frmIngresarSede.placa.value;
  var interior = document.frmIngresarSede.interior.value;
  var bloque = document.frmIngresarSede.bloque.value;
               
                
    </script>
     <%
        if(session.getAttribute("mensajes") != null){
          out.println((String)session.getAttribute("mensajes"));
        }
          session.removeAttribute("mensajes");
      %>
    
     <P align="center" class="celdatabla">
     Los campos marcados con (*) son obligatorios</P>
      <P>
        <a href="javascript:window.history.back()">
          <img src="<%=request.getContextPath() + "/images/BACK1-1.gif"%>" border="0"/>
        </a>
      
  </P>
     </form>
    </DIV>
    <P align="center"></P> 
    <% cf.closeConnection(consultas.getConn());%>
  </body>
</html>
